<?php
// File Security Check
if ( ! empty( $_SERVER['SCRIPT_FILENAME'] ) && basename( __FILE__ ) == basename( $_SERVER['SCRIPT_FILENAME'] ) ) :
	die ( 'You do not have sufficient permissions to access this page!' );
endif;

require_once 'engine/bootstrap.php';

/*
	Add your code below.
*/
register_sidebar(array(
        'id'=> 'home-staff-sidebar',
        'name' => 'Home Staff Sidebar',
        'before_widget' => '<div class="widget staff-widget">',
        'after_widget' => '</div>',
        'before_title' => '<h3>',
        'after_title' => '</h3>',
));

register_sidebar(array(
        'id'=> 'service-single-sidebar',
        'name' => 'Service Sidebar',
        'before_widget' => '<div class="widget">',
        'after_widget' => '</div>',
        'before_title' => '<h3>',
        'after_title' => '</h3>',
));

add_image_size( 'footer-thumbnail', 72, 50, true );

error_reporting(E_ERROR | E_PARSE);


/* =================================== */
// UNFORMAT TEXT 
/* =================================== */
function my_formatter($content) {
	$new_content = '';
	$pattern_full = '{(\[raw\].*?\[/raw\])}is';
	$pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
	$pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);

	foreach ($pieces as $piece) {
		if (preg_match($pattern_contents, $piece, $matches)) {
			$new_content .= $matches[1];
		} else {
			$new_content .= wptexturize(wpautop($piece));
		}
	}

	return $new_content;
}
add_filter('the_content', 'my_formatter', 99);
add_filter('widget_text', 'my_formatter', 99);

//add_filter( 'the_content', 'do_shortcode' );

/*
* @since 3.0.1, modified back to default WordPress shortcode format. (backward compatible for customer)
* no more using class.
* jQuery ui enqueued in footer via javascript.php, not sure since which version.
*
* How to use?
* [accordion class="accord1" active="2"]
* [slide name="slide1"]Content 1[/slide]
* [slide name="slide2"]Content 2[/slide]
* [/accordion]
* 
*/
	
function accordion_wrapper_shortcode( $atts, $content = null ){

    extract(shortcode_atts(array(
    'class' => 'accord1', //accordion class
    'active' => 'false', //since 3.0.1 close by default
    ), $atts));

    $output = '';
    $output .= '[raw]<ul class="accordion '.$class.'">[/raw]';
    $output .= do_shortcode($content) ;
    $output .= '[raw]</ul>[/raw]';
    
 	//added @since version 2.6 to allow open tab by default.
 	//uses jQuery UI version 1.8.15
    //jquery initialise individual accordions.
    $output .= "[raw]<script type='text/javascript'>jQuery(document).ready(function() {jQuery( \".".$class."\" ).accordion([/raw]";

    //if user wants to open any tab be default, user will set active='1'
    if(isset($active)){
    //the first tab is actually 0, so we use active tab minus 1.
    if($active != 'false'){ //fixed since 3.0.1
		$active = $active-1;
    }	
    $output .= "[raw]{ active: ".$active.", heightStyle: \"content\", autoHeight: true, header: \".opener\", collapsible: true, event: \"click\"}[/raw]";
    }

    $output .= "[raw]);});</script>[/raw]";
    
    return $output;	
}

add_shortcode('accordion','accordion_wrapper_shortcode');
    
    	
function accordion_slide_shortcode( $atts, $content = null ) {

    extract(shortcode_atts(array(), $atts));
    $slide = $atts['name'];
    $output = '';
    $output .= '[raw]<li><a href="#" class="opener"><span class="title">' .$slide. '</span></a>[/raw]';
    $output .= '[raw]<div class="slide-holder"><div class="slide">[/raw]';

    $output .= '' . do_shortcode($content) .'';

    $output .= '[raw]</div></div></li>[/raw]';
    return $output;
}	

add_shortcode('slide','accordion_slide_shortcode');

